Fix integers
n
,
r
,
s
1
,
.
.
.
,
s
l
n,r,s_{1},...,s_{l}
and let
S
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
\mathcal {S}(n,r;s_{1},...,s_{l})
be the set of all integral, projective and nondegenerate varieties
V
V
of degree
s
1
s_{1}
and dimension
n
n
in the projective space
P
r
\mathbf {P}^{r}
, such that, for all
i
=
2
,
.
.
.
,
l
i=2,...,l
,
V
V
does not lie on any variety of dimension
n
+
i
−
1
n+i-1
and degree
>
s
i
>s_{i}
. We say that a variety
V
V
satisfies a flag condition of type
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
(n,r;s_{1},...,s_{l})
if
V
V
belongs to
S
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
\mathcal {S}(n,r;s_{1},...,s_{l})
. In this paper, under the hypotheses
s
1
>>
.
.
.
>>
s
l
s_{1}>>...>>s_{l}
, we determine an upper bound
G
h
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
G^{h}(n,r;s_{1},...,s_{l})
, depending only on
n
,
r
,
s
1
,
.
.
.
,
s
l
n,r,s_{1},...,s_{l}
, for the number
G
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
:=
m
a
x
{
p
g
(
V
)
:
V
∈
S
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
}
G(n,r;s_{1},...,s_{l}):= {max} {\{} p_{g}(V) : V\in \mathcal {S}(n,r;s_{1},...,s_{l}){\}}
, where
p
g
(
V
)
p_{g}(V)
denotes the geometric genus of
V
V
. In case
n
=
1
n=1
and
l
=
2
l=2
, the study of an upper bound for the geometric genus has a quite long history and, for
n
≥
1
n\geq 1
,
l
=
2
l=2
and
s
2
=
r
−
n
s_{2}=r-n
, it has been introduced by Harris. We exhibit sharp results for particular ranges of our numerical data
n
,
r
,
s
1
,
.
.
.
,
s
l
n,r,s_{1},...,s_{l}
. For instance, we extend Halphen’s theorem for space curves to the case of codimension two and characterize the smooth complete intersections of dimension
n
n
in
P
n
+
3
\mathbf {P}^{n+3}
as the smooth varieties of maximal geometric genus with respect to appropriate flag condition. This result applies to smooth surfaces in
P
5
\mathbf {P}^{5}
. Next we discuss how far
G
h
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
G^{h}(n,r;s_{1},...,s_{l})
is from
G
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
G(n,r;s_{1},...,s_{l})
and show a sort of lifting theorem which states that, at least in certain cases, the varieties
V
∈
S
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
V\in \mathcal {S}(n,r;s_{1},...,s_{l})
of maximal geometric genus
G
(
n
,
r
;
s
1
,
.
.
.
,
s
l
)
G(n,r;s_{1},...,s_{l})
must in fact lie on a flag such as
V
=
V
s
1
n
⊂
V
s
2
n
+
1
⊂
.
.
.
⊂
V
s
l
n
+
l
−
1
⊂
P
r
V=V_{s_{1}}^{n}\subset V_{s_{2}}^{n+1}\subset ...\subset V_{s_{l}}^{n+l-1}\subset {\mathbf {P}^{r}}
, where
V
s
j
V^{j}_{s}
denotes a subvariety of
P
r
\mathbf {P}^{r}
of degree
s
s
and dimension
j
j
. We also discuss further generalizations of flag conditions, and finally we deduce some bounds for Castelnuovo’s regularity of varieties verifying flag conditions.